<%-- 
    Document   : index
    Created on : Sep 15, 2011, 8:22:27 AM
    Author     : Arturia
--%>

<%@page import="java.io.InputStream"%>
<%@page import="java.util.Properties"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Search result</title>
        <link href="css/style.css" rel="stylesheet" type="text/css"/>
        <link href="css/bannerstyle.css" rel="stylesheet" type="text/css"/>
        <link href="css/TableCSS.css" rel="stylesheet" type="text/css"/>

        <link href="css/thumbnail_css.css" rel="stylesheet" type="text/css"/>

        <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />

        <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
        <%@taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x" %>
        <script type="text/javascript">
            function setVisibility(showUser, isAdmin){
                if(showUser == "true"){
                    document.getElementById("user").style.visibility = "visible";
                    document.getElementById("loggeduser").style.visibility = "hidden";
                }else if(showUser == "false" && isAdmin == "true"){
                    document.getElementById("loggeduser").style.visibility = "visible";
                    document.getElementById("user").style.visibility = "hidden";
                    document.getElementById("user_link").textContent = "| Admin";
                    document.getElementById("user_link").href = "admin.jsp";
                }else if(showUser == "false" && isAdmin == "false"){
                    document.getElementById("loggeduser").style.visibility = "visible";
                    document.getElementById("user").style.visibility = "hidden";
                    document.getElementById("user_link").textContent = "| View Cart";
                    document.getElementById("user_link").href = "viewcart.jsp";
                }
                slideit();
            }

            var image1=new Image();
            image1.src="images/newrelease.jpg";
            var image2=new Image();
            image2.src="images/bestseller.jpg";
            var step=1;

            function checkSearch(){
                if (document.getElementById("searchText").value.toString().length == 0){
                    alert("Must input somrthing!")
                    return false;
                }else{
                    return true;
                }
            }
            function slideit()
            {
            //if browser does not support the image object, exit.
            if (!document.images)
            return
            document.images.slide.src=eval("image"+step+".src")
            if (step<2)
            step++
            else
            step=1
            //call function "slideit()" every 2.5 seconds
            setTimeout("slideit()",5000)
            }
        </script>
        <%
                    String loggedUser = (String) session.getAttribute("USER");
                    String showUser = "";
                    String isAdmin = "";
                    if (loggedUser == null) {
                        showUser = "true";
                    } else {
                        showUser = "false";
                        isAdmin = (String) session.getAttribute("ISADMIN");
                        if (isAdmin == null || isAdmin == "false") {
                            isAdmin = "false";
                        } else {
                            isAdmin = "true";
                        }
                    }
        %>
    </head>
    <body onload='setVisibility("<%=showUser%>", "<%=isAdmin%>")'>
        <%
                    String strCatSearch = (String) request.getAttribute("CATEGORY");
                    boolean isCatSearch = false;                    
                    if (strCatSearch == null || strCatSearch == "false") {
                        isCatSearch = false;
                    } else {
                        isCatSearch = true;
                    }
        %>
        <div id="header-wrap">
            <div id="header">
                <div style="margin:0px; text-align: left; float: left;"> <span style="color: #FFFFFF; font-family:'Arial Black',Gadget,sans-serif; font-size: 20px; font-weight: bold; letter-spacing: -2px;"><a href="index.jsp" style="color: #FFF; text-decoration: none;" title="Awesomebooks.com">AWESOMEBOOKS</a></span> <a style="color: #FFF; font-size: 18px; font-family: Georgia, 'Times New Roman', Times, serif; font-style:italic; font-weight:normal; text-decoration: none;" href="index.jsp" title="Find your own book">Find your own book</a> 	</div>
                <ul class="menu">

                    <!-- Begin Simple Item Without Drop -->
                    <li class="">
                        <a href="newrelease.jsp">New Release</a>
                    </li>
                    <li class="">
                        <a href="bestseller.jsp">Best Seller</a>
                    </li>
                    <li class="">
                        <a href="bookreview.jsp">Books Review</a>
                    </li>

                    <li class="drop">
                        <a href="#">Catalogs</a>
                        <span class="toggle">&nbsp;</span>
                        <ul>
                            <li><a href="Controller?Action=Search&searchText=literature&Category=true">Literature</a></li>
                            <li><a href="Controller?Action=Search&searchText=life style&Category=true">Life Style</a></li>
                            <li><a href="Controller?Action=Search&searchText=tutorial&Category=true">Tutorial</a></li>
                            <li><a href="Controller?Action=Search&searchText=discovery&Category=true">Discovery</a></li>
                            <li><a href="Controller?Action=Search&searchText=science&Category=true">Science</a></li>
                            <li><a href="Controller?Action=Search&searchText=kids&Category=true">Kids</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
            <div id="underheader">
                <form action="Controller" onsubmit="return checkSearch()" method="POST">

                    <span id="searchbox" style="width:50%">

                        <input id="searchText" name="searchText" type="text" style="width:250px; border:1px solid #333333" />
                        <input name="Action" type="submit" value="Search" id="button" />

                    </span>
                    <span id="user" style="width:25%">
                        <a href="login.jsp">Login</a> |
                        <a href="register.jsp">Register</a>
                    </span>
                    <span id="loggeduser" style="width:25%;position: relative; left: -180px; visibility: hidden">
                        <a><%=loggedUser%></a>
                        <a href="Controller?Action=Logout">(Logout)</a>
                        <a href="viewcart.jsp" id="user_link">| View Cart</a>
                    </span>
                </form>
            </div>
        </div>
        <center>
            <div id="banner">
                <img alt="" height="380" src="images/bestseller.jpg" width="800" style="padding:2px"/></div>

            <c:set var="searchtxt" value="${sessionScope.SEARCHSTRING}"/>
            <div id="content-header" style="height: 50px">
                <ul>
                    <a>SEARCH RESULT</a>
                </ul>
            </div>
            <form id="content">

                <table>
                    <tr>
                        <%
                                    if (isCatSearch == false) {
                        %>
                        <x:forEach var="node" select="$doc//*[contains((translate(title, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')), $searchtxt) or contains((translate(author,'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')), $searchtxt)]">
                            <c:set var="count" value="${count+1}"/>
                            <td>
                                <a href="bookdetail.jsp?bookID=<x:out select="$node//bookID"/>">
                                    <div class="gallerycontainer">
                                            <a class="thumbnail" href="bookdetail.jsp?bookID=<x:out select="$node//bookID"/>">
                                                <img alt="" src="covers/<x:out select="$node//imageLink"/>" width="103px" border="0"/>
                                                <span><img alt="" src="covers/<x:out select="$node//imageLink"/>" width="300px"/>
                                                    <br/><x:out select="title"/></span>
                                            </a>
                                        </div>
                                 <div id="case"><x:out select="$node//title"/></div>
                                </a>
                                   
                               
                            </td>
                            <c:if test="${count % 3 == 0}">
                                <%-- Check if the tr is more than 3 items then lwe move to a new tr --%>
                            </tr>
                            <tr>
                            </c:if>
                        </x:forEach>
                        <%                                                  } else {
                        %>

                        <x:forEach var="node1" select="$doc//*[(translate(normalize-space(category), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')) = $searchtxt]">
                            <c:set var="count1" value="${count1+1}"/>
                            <td>
                                 <a href="bookdetail.jsp?bookID=<x:out select="$node1//bookID"/>">
                                    <div class="gallerycontainer">
                                            <a class="thumbnail" href="bookdetail.jsp?bookID=<x:out select="$node1//bookID"/>">
                                                <img alt="" src="covers/<x:out select="$node1//imageLink"/>" width="103px" border="0"/>
                                                <span><img alt="" src="covers/<x:out select="$node1//imageLink"/>" width="300px"/>
                                                    <br/><x:out select="title"/></span>
                                            </a>
                                        </div>
                                 <div id="case"><x:out select="$node1//title"/></div>
                                </a>
                            </td>
                            <c:if test="${count1 % 3 == 0}">
                                <%-- Check if the tr is more than 3 items then lwe move to a new tr --%>
                            </tr>
                            <tr>
                            </c:if>
                        </x:forEach>
                    <%                                }
                    %>
                </tr>
            </table>
        </form>
    </center>
</body>
</html>
